'''An auto respond to invite module with quite a few configurable aspects.'''
############################################################################
#    Copyright (C) 2006 by Robert Small                                    #
#    SmallR2002@Gmail.com                                                  #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation; either version 2 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program; if not, write to the                         #
#    Free Software Foundation, Inc.,                                       #
#    59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
############################################################################

__module_name__        = "bcinvite"
__module_version__     = "0.0.1"
__module_description__ = "An auto respond to invite module, quite configurable."

import xchat
import sys
import os

if (sys.path.count(os.path.dirname(__file__)) == 0):
    sys.path.append(os.path.dirname(__file__))

#  Pretty much essential.
import bcsettings
import bcmisc

if (bcsettings.modules_to_load.count("bcnotify") > 0):
    import bcnotify


def invite_handle(word, word_eol, userdata): #IGNORE:W0613
    '''
    Handle an invite, join or not as the case may be.
    @param word: all the data you need to work with, chopped up into small parts.
    @type word: string
    @param word_eol: all the data you need to work with, chopped from wherever you're starting from.
    @type word_eol: string
    @param userdata: custom object to pass back.
    @type userdata: object
    '''
    if ((bcsettings.auto_join_list_invite == True) and (bcsettings.auto_join_list.count(word[1]) > 0)) or (bcsettings.auto_join_all_invite == True) or ((bcsettings.auto_join_self_invite == True) and (xchat.get_info('nick') == word[1])):
        xchat.prnt('Automatically joining ' + word[0])
        xchat.command('join ' + word[0])
        
        if (bcsettings.modules_to_load.count("bcnotify") > 0):
            bcnotify.libnotify_send("You joined " + word[0], "You automatically joined  " + word[0] + " where you were invited by " + bcmisc.clean_text(word[1]), bcsettings.libnotify_urgency_inv)
        
    else:
        xchat.prnt('Not joining ' + word[0] + ' automatically')
        if (bcsettings.auto_join_reply == True):
            xchat.command('notice ' + word[1] + ' [Automatic Notice]' + xchat.get_info('nick') + " will review your request soon. (Either they dont have auto-join-on-invite on, or they don't have you on their auto-join-list.)")  
    return xchat.EAT_NONE